import config from "@/config"
import http from "@/utils/request"


export default {
  getRoleList: {
    url: `${config.API_URL}/role/list`,
    name: "获取角色列表",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
  addRole: {
    url: `${config.API_URL}/role/add`,
    name: "添加角色",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  updateRole: {
    url: `${config.API_URL}/role/update`,
    name: "更新角色",
    put: function (data) {
      return new Promise((resolve, reject) => {
        http.put(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteRole: {
    url: `${config.API_URL}/role/delete`,
    name: "删除角色",
    delete: function (data) {
      return new Promise((resolve, reject) => {
        http.delete(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  deleteRoleList: {
    url: `${config.API_URL}/role/deleteList`,
    name: "批量删除角色",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.post(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getRoleMenu: {
    url: `${config.API_URL}/role/menuList`,
    name: "获取角色已有菜单",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getRoleDepartment: {
    url: `${config.API_URL}/role/departmentList`,
    name: "获取角色已有菜单",
    get: function (param) {
      return new Promise((resolve, reject) => {
        http.get(this.url, param).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  setPermission: {
    url: `${config.API_URL}/role/permission`,
    name: "设置角色权限",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getRoleGridList: {
    url: `${config.API_URL}/modRole/modList`,
    name: "获取角色已有控制台列表",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  setRoleGrid: {
    url: `${config.API_URL}/modRole/chooseMod`,
    name: "设置角色控制台权限",
    post: function (data) {
      return new Promise((resolve, reject) => {
        http.postParam(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },

  getGridList: {
    url: `${config.API_URL}/mod/modTree`,
    name: "获取控制台列表",
    get: function (data) {
      return new Promise((resolve, reject) => {
        http.get(this.url, data).then((response) => {
          resolve(response)
        }).catch((error) => {
          resolve(error.data)
        })
      })
    }
  },
}
